package com.jian.java;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Jiange
 * @create 2021-04-06-14:55
 */
public class MyServlet2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(request.getAttribute("key"));
        System.out.println("参数是"+request.getParameter("name"));
//        ServletOutputStream outputStream = response.getOutputStream();
//        FileInputStream fileInputStream = new FileInputStream("D:\\自己编程前端练习文件\\tupian\\2.jpg");
//        byte[] bytes = new byte[1024];
//        System.out.println(response.getCharacterEncoding());
//        response.setHeader("content-type","text/plain;charset=utf-8");
//        int read;
//        while ((read=fileInputStream.read(bytes)) != -1){
//            outputStream.write(bytes,0,read);
//        }
//        outputStream.close();
//        fileInputStream.close();

//        response.setStatus(401);
//        response.setCharacterEncoding("utf-8");
//        response.setHeader("content-type","text/plain;charset=utf-8");
//        response.setContentType("text/plain;charset=utf-8");//同时设置了服务器和客户端 必须要在获取流对象之前调用
//        System.out.println(response.getCharacterEncoding());
//        PrintWriter writer = response.getWriter();
//        writer.write("建哥最帅");
        response.setContentType("ext/plain;charset=utf-8");
        response.getWriter().write("客户端跳转");
    }
}
